using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using NUnit.Framework;
using WPFUtilities;

namespace WPFUtilitiesUnitTests
{
    [TestFixture]
    public class BreadthFirstVisualTreeIteratorTests
    {
        [Test]
        public void Find()
        {
            DockPanel root = new DockPanel();
            root.Name = "root";
            Button childOne = new Button();
            childOne.Name = "childOne";
            root.Children.Add(childOne);
            List<DependencyObject> objects = new List<DependencyObject>();
            BreadthFirstVisualTreeIterator iterator = new BreadthFirstVisualTreeIterator();
            foreach (DependencyObject dependencyObject in iterator.GetNodes(root))
            {
                objects.Add(dependencyObject);
            }
            Assert.AreEqual(2, objects.Count);
            Assert.AreSame(root, objects[0]);
            Assert.AreSame(childOne, objects[1]);
            
        }

        [Test]
        public void ThreeLevelsDeep()
        {
            DockPanel root = new DockPanel();
            DockPanel innerPanel = new DockPanel();
            Button levelTwoButton = new Button();
            Button levelThreeButton = new Button();
            root.Children.Add(innerPanel);
            root.Children.Add(levelTwoButton);
            innerPanel.Children.Add(levelThreeButton);
            List<DependencyObject> objects = new List<DependencyObject>();
            BreadthFirstVisualTreeIterator iterator = new BreadthFirstVisualTreeIterator();
            foreach (DependencyObject dependencyObject in iterator.GetNodes(root))
            {
                objects.Add(dependencyObject);
            }
            Assert.AreEqual(4, objects.Count);
            Assert.AreSame(root, objects[0]);
            Assert.AreSame(innerPanel, objects[1]);
            Assert.AreSame(levelTwoButton, objects[2]);
            Assert.AreSame(levelThreeButton, objects[3]);
        }
    }
}